//游戏交互//////////////////////////////////////////////////////////////////////////////////////
//角色对话框---------------------------------
var current_mouth_x;
var current_mouth_y;
var playerLandId;
var playerPropId;

////landState==>>>1未开垦2未种植3成长中5成熟待收割9收割后未翻地
function playerOperate(landState,landSort) {
	let land = current_player_farm_lands_detail.get('land_'+landSort);
	if(checkEmpty(land)==false){//判断是否有效
		playerLandId = land.id;
	}
	//console.log('landSort==='+landSort);
	//console.log('current_player_farm_lands_detail==='+current_player_farm_lands_detail);
	//console.log('land==='+land);
	reset_point('playerFightDiv');
	//操作按钮
	let dom = $('#player_action_btns');
	dom.html('');
		
	let str = '';
	//是否需要开垦
	if(landState<=1){
		$('#player_action_title').html('待开垦');
		str = str + '<span class="player-fight-action" onclick="doPlayerAction(40)">[开垦]</span>';
	}else if(landState==2){
		$('#player_action_title').html('待种植');
		str = str + '<span class="player-fight-action" onclick="doPlayerAction(20)">[播种]</span>';
	}else if(landState==3){
		$('#player_action_title').html(land.cropsName+'未成熟');
		str = str + '<span class="player-fight-action" onclick="doPlayerAction(10)">[翻地]</span>';
		//str = str + '<span class="player-fight-action" onclick="doPlayerAction(20)">[播种]</span>';
		//str = str + '<span class="player-fight-action" onclick="doPlayerAction(30)">[收割]</span>';
		//str = str + '<span class="player-fight-action" onclick="doPlayerAction(40)">[开垦]</span>';
		str = str + '<br>';
		str = str + '<span class="player-fight-action" onclick="doPlayerAction(50)">[浇水]</span>';
		str = str + '<span class="player-fight-action" onclick="doPlayerAction(60)">[施肥]</span>';
		str = str + '<span class="player-fight-action" onclick="doPlayerAction(70)">[除草]</span>';
		str = str + '<span class="player-fight-action" onclick="doPlayerAction(80)">[杀虫]</span>';
	}else if(landState==5){
		$('#player_action_title').html(land.cropsName+'待收割');
		str = str + '<span class="player-fight-action" onclick="doPlayerAction(30)">[收割]</span>';
		str = str + '<span class="player-fight-action" onclick="doPlayerAction(31)">[再种]</span>';
	}else if(landState==9){
		$('#player_action_title').html(land.cropsName+'已收割');
		str = str + '<span class="player-fight-action" onclick="doPlayerAction(10)">[翻地]</span>';
	}else{
		$('#player_action_title').html('待翻地');
		str = str + '<span class="player-fight-action" onclick="doPlayerAction(10)">[翻地]</span>';
	}
	dom.append(str);
	$('#playerFightDiv').removeClass('dn');
}
function playerFightOver() {
	//初始化
	$('#playerFightDiv').addClass('dn');
	playerLandId = '';
}
///////////////////////////////////////////////////////////////////////////////////////////////
//显示用户交互页面信息
function doPlayerAction(type) {
	let srcUrl = '/game/1.0/sfg/action';
	if (type == 1) {//关闭
		playerFightOver();
	} else if (type == 10) {//翻地
		srcUrl = srcUrl + '/turn.js';
	} else if (type == 20) {//播种
		srcUrl = srcUrl + '/sow.js';
	} else if (type == 30) {//收割
		srcUrl = srcUrl + '/harvest.js';
	} else if (type == 40) {//开垦
		srcUrl = srcUrl + '/bring.js';
	} else if (type == 50) {//浇水
		srcUrl = srcUrl + '/watering.js';
	} else if (type == 60) {//施肥
		srcUrl = srcUrl + '/fertilize.js';
	} else if (type == 70) {//除草
		srcUrl = srcUrl + '/weed.js';
	} else if (type == 80) {//杀虫
		srcUrl = srcUrl + '/insecticidal.js';
		return;
	} else {//关闭
		playerFightOver();
	}
	//数据交互
	playerInteractiveServerAction(srcUrl);
}

//服务器交互请求
function playerInteractiveServerAction(srcUrl) {
	if (checkEmpty(playerLandId)) {
		showPersonalMessage(_game_name_, "请选择一块土地再进行操作");
		return;
	}
	$.ajax({
		type: "post",
		url: ajaxUrl + srcUrl + "?jobId=" + getTimeMs(),
		data: {
			token: window.localStorage.getItem('token'),
			sid: currentSID,
			gameId: 'SFG',
			playerLandId: playerLandId,
			playerPropId: playerPropId,
		},
		dataType: "json",
		success: function(request) {
			console.log(request);
			//刷新土地状态
			if (request.code != 0) {
				doErrorMessage(request.code, request.msg);
			} else {
				current_player_farm = request.data;
			}
		},
		error: function(error) {
			console.log(error);
		}
	});
}

//关闭用户交互页面信息
function closePlayerRoleInfoDiv() {
	showPlayerRoleInfoDiv(9999);
}